package Demo_zhuanshu01.X9;

//测试类
public class TestCave {
    public static void main(String[] args) {
        //实例化山洞
        Cave cave = new Cave();

            Thread thread1 = new Thread(cave,"田江余");
            Thread thread2 = new Thread(cave,"田大余");
            Thread thread3 = new Thread(cave,"田泥鳅");
            Thread thread4 = new Thread(cave,"生产队的大驴");
            Thread thread5 = new Thread(cave,"薛余江");
            Thread thread6 = new Thread(cave,"大驴");
            Thread thread7 = new Thread(cave,"疯狂的大余");
            Thread thread8 = new Thread(cave,"铁甲大余");
            Thread thread9 = new Thread(cave,"钢铁小余");
            Thread thread10 = new Thread(cave,"余");
            thread1.start();
            thread2.start();
            thread3.start();
            thread4.start();
            thread5.start();
            thread6.start();
            thread7.start();
            thread8.start();
            thread9.start();
            thread10.start();

    }
}
//编写山洞类
class Cave implements Runnable{
    @Override
    public void run() {
        //设置锁
        synchronized (this){
            System.out.println(Thread.currentThread().getName()+"正在通过");
            Cave cave = new Cave();
            Thread thread = new Thread(cave);
            try {
                thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

